import { HostConnConfType } from '@common'
import { BaseModelTreeNodeType } from '@renderer/types'

export type HostConnConfTreeNodeType = HostConnConfType &
  BaseModelTreeNodeType & {
    children?: HostConnConfTreeNodeType[]
  }

export type HostConnConfTreeType = HostConnConfTreeNodeType[]

export const useHostConnConfStore = defineStore('hostConnConfStore', () => {
  const { getMap, getList, getTree, getDirTree, getTreeMapAll, getTreeMap, load } =
    genAndLoadConfStatus(api.findHostConnConfs) as {
      getMap: () => Record<string, HostConnConfType>
      getList: () => HostConnConfTreeType
      getTree: () => HostConnConfTreeType
      getDirTree: () => HostConnConfTreeType
      getTreeMapAll: () => Record<string, HostConnConfTreeNodeType>
      getTreeMap: () => Record<string, HostConnConfTreeNodeType>
      load: () => Promise<void>
    }

  return {
    getMap,
    getList,
    getTree,
    getDirTree,
    getTreeMapAll,
    getTreeMap,
    load
  }
})
